import { getUserInfo } from '@/api/user.js'
export default {
  namespaced: true,
  state: {
    globalUser: { name: 123 },
    userId: localStorage.getItem('userId') || '',
    isAgreeProtocol:
      JSON.parse(localStorage.getItem('isAgreeProtocol')) || false
  },
  mutations: {
    setGlobalUser(state, data) {
      state.globalUser = data
      localStorage.setItem('globalUser', JSON.stringify(data))
    },
    setUserId(state, data) {
      state.userId = data
      localStorage.setItem('userId', data)
    },
    setIsAgreeProtocol(state, data) {
      localStorage.setItem('isAgreeProtocol', data)
      state.isAgreeProtocol = data
    }
  },
  actions: {
    getUserInfoAction({ commit }, data) {
      return new Promise((resolve) => {
        getUserInfo(data).then((res) => {
          console.log('用户信息', res)
          commit('setGlobalUser', res.data)
          commit('setUserId', res.data.id + '')
          resolve()
        })
      })
    }
  }
}
